package com.sk.bilibili.view.fragment.live;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.sk.bilibili.adapter.vlayout.main.LiveAdapter;
import com.sk.bilibili.bean.Live;
import com.sk.bilibili.callBack.LiveClickCallBack;
import com.sk.bilibili.model.fragment.live.RecommendModel;
import com.sk.bilibili.view.activity.LiveActivity;
import com.sk.bilibili.view.fragment.BaseRefreshFragment;

import java.util.List;

public class RecommendFragment extends BaseRefreshFragment<RecommendModel> implements LiveClickCallBack {

    private Integer typeId;
    private LiveAdapter liveAdapter;

    public RecommendFragment(Integer typeId) {
        this.typeId=typeId;
    }

    @Override
    protected void initAdapter(DelegateAdapter adapter) {
        liveAdapter = new LiveAdapter(getContext(), this);
        adapter.addAdapter(liveAdapter);
    }

    @Override
    public void onBottom() {
        model.loadMore(typeId);
    }

    @Override
    public void onRefresh() {
        model.refresh(typeId);
    }

    @Override
    public void onLiveClick(Live live) {
        LiveActivity.start(getContext(),live);
    }

    public void addLive(List<Live> lives) {
        liveAdapter.addData(lives);
    }

    public void setLive(List<Live> lives) {
        liveAdapter.setData(lives);
        cancelRefresh();
    }

}